﻿namespace DemoTest
{
    using Guia.Core;
    using Guia.Elements;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Test of an application.
    /// </summary>
    [TestClass]
    public class PersonApplicationTest
    {
        /// <summary>
        /// the local TestContext
        /// </summary>
        private TestContext testContextInstance;

        /// <summary>
        /// Application to test
        /// </summary>
        private Application application;

        /// <summary>
        /// The window of the application to test
        /// </summary>
        private Window window;

        /// <summary>
        /// Gets or sets TestContext.
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return this.testContextInstance;
            }

            set
            {
                this.testContextInstance = value;
            }
        }

        /// <summary>
        /// Initialize method
        /// </summary>
        [TestInitialize]
        public void MyTestInitialize()
        {
            this.application = Application.Start(@"WpfDemoApplication.exe");
            this.window = this.application.GetWindowByName("Sample Main Window");
        }

        /// <summary>
        /// Cleanup method
        /// </summary>
        [TestCleanup]
        public void MyTestCleanup()
        {
            if (this.application != null)
            {
                this.application.Stop();
            }
        }

        /// <summary>
        /// Tests an entire application.
        /// </summary>
        [TestMethod]
        public void TestEntireApp()
        {
            // Simulate user interactions
            this.window.Get<TextBox>("txtFirstname").Value = "Roger";
            this.window.Get<TextBox>("txtName").Value = "Smith";
            this.window.Get<ComboBox>("cmbNationality").GetItem("Switzerland").Select();
            this.window.Get<Button>("btnAdd").Invoke();
            DataGrid_WpfToolkit dataGrid = this.window.Get<DataGrid_WpfToolkit>("dataGrid");

            // Assertions
            Assert.AreEqual("Smith", dataGrid[0, 0].TextValue);
            Assert.AreEqual("Roger", dataGrid[0, 1].TextValue);
            Assert.AreEqual("Switzerland", dataGrid[0, 2].TextValue);
        }
    }
}
